//公共中间调用层
var bus_school = new Vue();

var common_fn_school = function () {
    this.configInfo = null;
    var self = this;


    //获取关系类 法一
    this.QueryObjectsGraph = function (userInfo, snapshots, entryObjects, relations, callBack) {
        var param = {
            "user": userInfo,
            "snapshots": snapshots,
            "entryObjects": entryObjects,
            "relations": relations,
            "queryFields": []
        }
        var url = getRootPath() + "/app/invoke?fun=QueryObjectsGraph";
        axios.post(url, param)
            .then(function (response) {
                if (typeof (response.data) == 'string') {
                    response.data = JSON.parse(response.data);
                }
                if (response.status == '200') {
                    callBack(response.data)
                }
            })
    },

        //获取关系类 法二
        this.QueryRelatedGraphNode = function (id, type, classRole, callBack) {
            var param = {
                "user": {
                    "type": "SysPerson",
                    "id": 1
                },
                "snapshots": null,
                "snapshotIgnored": 1,
                "entity": {
                    "id": id,
                    "type": type
                },
                "classRole": classRole
            }
            var url = getRootPath() + "/app/invoke?fun=QueryRelatedGraphNode"
            axios.post(url, param)
                .then(function (response) {
                    if (typeof (response.data) == 'string') {
                        response.data = JSON.parse(response.data);
                    }
                    if (response.status == '200') {
                        callBack(response.data)
                    }
                })
        },

        //创建批次，同时建立和订单关系
        this.CreateProductionSchedule = function (orderSheet, productionSchedule, callBack) {
            var param = {
                "appName": "Mes",
                "orderSheet": orderSheet,
                "productionSchedule": productionSchedule
            }
            var url = getRootPath() + "/app/invoke?fun=CreateProductionSchedule"
            axios.post(url, param)
                .then(function (response) {
                    if (typeof (response.data) == 'string') {
                        response.data = JSON.parse(response.data);
                    }
                    if (response.status == '200') {
                        callBack(response.data)
                    }
                })
        },

        //获取当前对象的snapshot 
        this.GetCurrentSnapshot = function (ID, type, typeNo, callBack) {
            var param = {
                "entry": {
                    "id": ID,
                    "type": type
                },
                "type": typeNo
            }
            var url = getRootPath() + "/app/invoke?fun=GetCurrentSnapshot"
            axios.post(url, param)
                .then(function (response) {
                    if (typeof (response.data) == 'string') {
                        response.data = JSON.parse(response.data);
                    }
                    if (response.status == '200') {
                        callBack(response.data)
                    }
                })
        },

        //PBOM转MBOM
        this.PBom2MBomDirectly = function (order, product, snapshotId, callBack) {
            var param =
                {
                    "order": order,
                    "product": product,
                    "snapshot": {
                        "id": snapshotId,
                        "type": "SysSnapshot",
                        "properties": {
                            "type": "2"
                        },
                    },
                    "createProductLayer": true,
                    "outSourceJoin": false,
                    "level": 0,
                    "connectionId": 1,
                    "appName": "Mes",
                    "factory": "标准工厂",
                    "service": "JRJ_ITM",
                    "role": []
                }
            var url = getRootPath() + "/app/invoke?fun=PBom2MBomDirectly";
            axios.post(url, param)
                .then(function (response) {
                    if (typeof (response.data) == 'string') {
                        response.data = JSON.parse(response.data);
                    }
                    if (response.status == '200') {
                        callBack(response.data)
                    }
                })
        },

        //APS排产
        this.Schedule_AutoSchedule = function (productionSchedules, userInfo, callBack) {
            var param = {
                "productionSchedules": productionSchedules,
                "user": userInfo,
                "connectionId": 0,
                "appName": "MES",
                "factory": "标准工厂",
                "service": "JRJ_ITM",
                "role": []
            }
            var url = getRootPath() + "/app/invoke?fun=Schedule_AutoSchedule";
            axios.post(url, param)
                .then(function (response) {
                    if (typeof (response.data) == 'string') {
                        response.data = JSON.parse(response.data);
                    }
                    if (response.status == '200') {
                        callBack(response.data)
                    }
                })
        },

        //APS排产
        this.SaveMonthScheduleTable = function (scheduleCellList, userInfo, callBack) {
            var param = {
                "scheduleCellList": scheduleCellList,
                "user": userInfo,
                "connectionId": 0,
                "appName": "MES",
                "factory": "标准工厂",
                "service": "JRJ_ITM",
                "role": []
            }
            var url = getRootPath() + "/app/invoke?fun=SaveMonthScheduleTable";
            axios.post(url, param)
                .then(function (response) {
                    if (typeof (response.data) == 'string') {
                        response.data = JSON.parse(response.data);
                    }
                    if (response.status == '200') {
                        callBack(response.data)
                    }
                })
        },

        //改变计划状态
        this.ProductionSheduleStateChange = function (productionSchedule, state, userInfo, callBack) {
            var param = {
                "productionSchedule": productionSchedule,
                "state": state,
                "description": "",
                "startDate": "",
                "user": userInfo,
                "connectionId": 0,
                "appName": "MES",
                "factory": "标准工厂",
                "service": "JRJ_ITM",
                "role": []
            }
            var url = getRootPath() + "/app/invoke?fun=ProductionSheduleStateChange";
            axios.post(url, param)
                .then(function (response) {
                    if (typeof (response.data) == 'string') {
                        response.data = JSON.parse(response.data);
                    }
                    if (response.status == '200') {
                        callBack(response.data)
                    }
                })
        },

        //发批量布车间计划
        this.WorkShopPlanBatchPublish = function (userInfo, semifinisheds, snapshots, teamObjids, callBack) {
            var param = {
                "user": userInfo,
                "semifinisheds": semifinisheds,
                "snapshots": snapshots,
                "teamObjids": teamObjids
            }
            var url = getRootPath() + "/app/invoke?dll=JridgeMesSTD_AdditionalService.dll&clstype=JridgeMesSTD_AdditionalService.ProductionScheduleMgr&fun=WorkShopPlanBatchPublish";
            axios.post(url, param)
                .then(function (response) {
                    if (typeof (response.data) == 'string') {
                        response.data = JSON.parse(response.data);
                    }
                    if (response.status == '200') {
                        callBack(response.data)
                    }
                })
        },

        //获取发布到班组的计划，合并多张表
        this.QueryAssginSheetOneSet = function (filters,queryclasses, queryFields, userInfo, callBack) {
            var param = {
                "filters": filters,
                "orderItems": [],
                "queryclasses": queryclasses,
                "queryFields": queryFields,
                "isQueryPreNext": true,
                "isQueryNextConsiderParent": true,
                "user": userInfo
            }
            var url = getRootPath() + "/app/invoke?dll=JridgeMesSTD_AdditionalService.dll&clstype=JridgeMesSTD_AdditionalService.AssignSheetMgr&fun=QueryAssginSheetOneSet";
            axios.post(url, param)
                .then(function (response) {
                    if (typeof (response.data) == 'string') {
                        response.data = JSON.parse(response.data);
                    }
                    if (response.status == '200') {
                        callBack(response.data)
                    }
                })
        }





}


